#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
#include <memory.h>
using namespace std;
 
struct node {
    int w, v;
    node(int v, int w) {
        this->w = w;
        this->v = v;
    }
};
 
bool vis[10005];
queue<int> q;
vector<node> G[10005];
int tx[10005], d[10005];
int n, m;
 
bool spfa() {
    memset(d, 0xef, sizeof(d));
    d[0] = 0;
    q.push(0);
    tx[0] = 1;
    while(!q.empty()) {
        int u = q.front();
        q.pop();
        vis[u] = 0;
        for(unsigned i = 0; i < G[u].size(); ++i) {
            int v = G[u][i].v;
            int dis = G[u][i].w;
            if (d[v] < d[u] + dis) {
                d[v] = d[u] + dis;
                if (++tx[v] >= 40) {
                    return 0;
                }
                if (!vis[v]) {
                	q.push(v);
                	vis[v] = 1;
				}
            }
        }
    }
	return 1;
}

int main() {
    int a, b, c, t;
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= m; ++i) {
        scanf("%d %d %d", &t, &a, &b);
        if (t == 3) {
            G[a].push_back(node(b, 0));
            G[b].push_back(node(a, 0));
        } else {
            scanf("%d", &c);
            if (t == 1) {
                G[a].push_back(node(b, c));
            } else {
                G[b].push_back(node(a, -c));
            }
        }
    }
 	
	for (int i = 1; i <= n; ++i) {
 		G[0].push_back(node(i, 0));
	}
 	
    if (spfa()) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
	
    return 0;
}
